//原型链继承
function father(){
    this.name='fa'
}

function son(){
    this.name='son'
}

son.prototype=new father()


//借用构造函数继承

function son2(){
    father.call(this)
}

//组合继承
function son3(){
    father.call(this)
}
son3.prototype=new father()

//原型式继承
function object(obj){
    function f(){}
    f.prototype=obj
    return new f()
}
let son4={
    name='son4'
}
let s=object(son4)

//寄生继承 原型式继承基础上给构造函数增加属性
function object2(obj){
    let ss=object(obj)
    ss.say=function(){
        console.log('Hi!')
    }
}

//寄生组合继承 (子类的原型) 比原型式继承多了一步：将构造函数指向自己
function inherit(son,father){
    son.prototype=Object.create(father.prototype)
    son.prototype.constructor=son
}

function superType(name){
    this.name=name
    this.sayName=function(){
        console.log(name)
    }
}

superType.prototype.sayHi=function(){
    console.log('super hi')
}

function subType(name,age){
    this.age=age
    father.call(this,name)
}

subType.prototype.sayHi=function(){
    console.log('sub hi')
}

inherit(subType,father)


